import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:safetymonitor/app/components/custom_app_bar.dart';
import 'package:safetymonitor/app/components/custom_filter_right_sheet.dart';
import 'package:safetymonitor/app/core/core.dart';
import 'package:safetymonitor/app/core/ext/ext.dart';
import 'package:safetymonitor/app/core/values/colors.dart';
import 'package:safetymonitor/modules/home/new_alarm_warning_page/completed/view.dart';
import 'package:safetymonitor/modules/home/new_alarm_warning_page/controller.dart';
import 'package:safetymonitor/modules/home/new_alarm_warning_page/device_completed/view.dart';
import 'package:safetymonitor/modules/home/new_alarm_warning_page/device_no_completed/view.dart';
import 'package:safetymonitor/modules/home/new_alarm_warning_page/no_completed/view.dart';

/// 新的预警报警数据
class NewAlarmWarningPagePage extends StatelessWidget {
  NewAlarmWarningPagePage({super.key});

  final controller = Get.put(NewAlarmWarningPageController());

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
      init: controller,
      builder: (_) {
        return Scaffold(
          key: controller.rightScaffoldKey,
          backgroundColor: AppColors.bg_color_grey,
          appBar: CustomAppBar(
            titleText: '预警报警',
            actions: [
              Visibility(
                visible: controller.index==2||controller.index==4,
                child: Container(
                    padding: EdgeInsets.only(left: 10.w, right: 15.w, bottom: 10.w, top: 10.w),
                    child: Text(
                      '筛选',
                      style: TextStyle(fontSize: 16.sp, fontWeight: FontWeight.w400, color: Colors.deepPurple),
                    )).clickOnce(controller.onFilterButtonPressed),
              ),
            ],
          ),
          body: Column(
            children: [
              Container(
                alignment: Alignment.center,
                padding: EdgeInsets.all(2.w),
                margin: EdgeInsets.symmetric(horizontal: 10.w),
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.circular(4.w),
                  border: Border.all(color: const Color(0xff2267C0), width: 1.w),
                ),
                child: Column(
                  children: [
                    Row(
                      children: [
                        Expanded(
                          child: Container(
                            decoration: BoxDecoration(
                              color: controller.selectButtonFirst ? const Color(0xff2267C0) : const Color(0x7ee8edf3),
                              borderRadius: BorderRadius.circular(4.r),
                            ),
                            child: Container(
                              padding: EdgeInsets.all(5.w),
                              alignment: Alignment.center,
                              child: Text(
                                '预警报警待完成',
                                style: controller.selectButtonFirst ? const TextStyle(color: Colors.white) : const TextStyle(color: Color(0xff2267C0)),
                              ),
                            ),
                          ).clickOnce(() {
                            if (controller.selectButtonFirst) {
                              return;
                            }
                            controller.selectButtonFirst = true;
                            controller.selectButtonSecond = false;
                            controller.selectButtonThird = false;
                            controller.selectButtonFourth = false;
                            controller.index = 1;
                            controller.dataType = 1;
                            controller.updateInfo();
                          }),
                        ),
                        AppGaps.hGap2,
                        Expanded(
                          child: Container(
                            decoration: BoxDecoration(
                              color: controller.selectButtonSecond ? const Color(0xff2267C0) : const Color(0x7ee8edf3),
                              borderRadius: BorderRadius.circular(4.r),
                            ),
                            child: Container(
                              padding: EdgeInsets.all(5.w),
                              alignment: Alignment.center,
                              child: Text(
                                '设备离线已完成',
                                style: controller.selectButtonSecond ? const TextStyle(color: Colors.white) : const TextStyle(color: Color(0xff2267C0)),
                              ),
                            ),
                          ).clickOnce(() {
                            if (controller.selectButtonSecond) {
                              return;
                            }
                            controller.selectButtonFirst = false;
                            controller.selectButtonSecond = true;
                            controller.selectButtonThird = false;
                            controller.selectButtonFourth = false;
                            controller.index = 2;
                            controller.dataType = 3;
                            controller.updateInfo();
                          }),
                        ),
                      ],
                    ),
                    AppGaps.vGap2,
                    Row(
                      children: [
                        Expanded(
                          child: Container(
                            decoration: BoxDecoration(
                              color: controller.selectButtonThird ? const Color(0xff2267C0) : const Color(0x7ee8edf3),
                              borderRadius: BorderRadius.circular(4.r),
                            ),
                            child: Container(
                              padding: EdgeInsets.all(5.w),
                              alignment: Alignment.center,
                              child: Text(
                                '设备离线待完成',
                                style: controller.selectButtonThird ? const TextStyle(color: Colors.white) : const TextStyle(color: Color(0xff2267C0)),
                              ),
                            ),
                          ).clickOnce(() {
                            if (controller.selectButtonThird) {
                              return;
                            }
                            controller.selectButtonFirst = false;
                            controller.selectButtonSecond = false;
                            controller.selectButtonThird = true;
                            controller.selectButtonFourth = false;
                            controller.index = 3;
                            controller.dataType = 3;
                            controller.updateInfo();
                          }),
                        ),
                        AppGaps.hGap2,
                        Expanded(
                          child: Container(
                            decoration: BoxDecoration(
                              color: controller.selectButtonFourth ? const Color(0xff2267C0) : const Color(0x7ee8edf3),
                              borderRadius: BorderRadius.circular(4.r),
                            ),
                            child: Container(
                              padding: EdgeInsets.all(5.w),
                              alignment: Alignment.center,
                              child: Text(
                                '预警报警已完成',
                                style: controller.selectButtonFourth ? const TextStyle(color: Colors.white) : const TextStyle(color: Color(0xff2267C0)),
                              ),
                            ),
                          ).clickOnce(() {
                            if (controller.selectButtonFourth) {
                              return;
                            }
                            controller.selectButtonFirst = false;
                            controller.selectButtonSecond = false;
                            controller.selectButtonThird = false;
                            controller.selectButtonFourth = true;
                            controller.index = 4;
                            controller.dataType = 1;
                            controller.updateInfo();
                          }),
                        )
                      ],
                    ),
                  ],
                ),
              ),
              Expanded(
                child: _selectPage(controller.index),
              ),
            ],
          ),
          endDrawer: Container(
            width: AppDimens.sw - 70.w,
            height: AppDimens.sh,
            color: Colors.white,
            child: controller.index==4? _getFilterWidget2() : _getFilterWidget(),
          ),
        );
      },
    );
  }

  /// 选择的界面
  Widget _selectPage(int index) {
    switch (index) {
      case 1:
        //设备预警报警待完成
        return AlarmNoCompletedPage();
      case 2:
        //设备离线已完成
        return DeviceOffLineCompletedPage();
      case 3:
        //设备离线待完成
        return DeviceOffLineNoCompletedPage();
      case 4:
        //设备预警报警已完成
        return AlarmCompletedPage();
      default:
        return Container();
    }
  }

  ///获取右侧筛选样式
  Widget _getFilterWidget() {
    return CustomFilterRightSheet(
      dataList: controller.filterList,
      onConfirm: controller.screenConfirm,
      topSpacing: AppGaps.vGap20,
      isRadio: true,
    );
  }

  ///获取右侧筛选样式
  Widget _getFilterWidget2() {
    return CustomFilterRightSheet(
      dataList: controller.filterList2,
      onConfirm: controller.screenConfirm2,
      topSpacing: AppGaps.vGap20,
      isRadio: true,
    );
  }
}
